package com.pf.controller;

import com.pf.dto.LoginUserReq;
import com.pf.dto.RegisterUserReq;
import com.pf.dto.ResultResp;
import com.pf.service.UserService;
import com.pf.utils.ResultRespUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2021/12/19 20:10
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户注册
     *
     * @param req
     * @return
     */
    @PostMapping("/register")
    public ResultResp register(@RequestBody @Valid RegisterUserReq req) {
        userService.registerUser(req);
        return ResultRespUtils.success();
    }

    /**
     * 用户登录
     *
     * @param req
     * @return
     */
    @PostMapping("/login")
    public ResultResp login(@RequestBody @Valid LoginUserReq req) {
        userService.loginUser(req);
        return ResultRespUtils.success();
    }

    /**
     * 激活账号
     *
     * @param activationCode
     * @return
     */
    @GetMapping("/activateUser")
    public ResultResp activateUser(@RequestParam("activationCode") String activationCode) {
        userService.activateUser(activationCode);
        return ResultRespUtils.success();
    }
}
